package com.itheima.HomeWork_day09;

/*
自然排序要在类中实现接口
 */
public class People implements Comparable<People> {
    private String name;
    private int age;

    public People() {
    }

    public People(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(People o) {

        //排序规则，要求根据年龄从大到小排序
        int result1 = o.getAge() - this.age;
        //当年龄相同时根据姓名先后进行排序
        result1 = result1 == 0 ? o.getName().compareTo(this.name) : result1;
        return result1;
    }
}
